package com.zzj.socket.server;

import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;

/**
 * @author: zzj
 * @date: 2017/12/19
 * Time: 14:23
 */
public class Main {
    public static int port = 9898;
    public static void main(String[] args) {

        NioSocketAcceptor acceptor = new NioSocketAcceptor();

        try {
            //设置handler
            acceptor.setHandler(new MyHandler());
            //设置过滤器
            acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
            //绑定端口号
            acceptor.bind(new InetSocketAddress(port));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
